﻿function ShowGroup(groupId) {
    $("div[id^=gp]").hide();   
    document.getElementById('gp'+groupId).style.display = '';
    $('li', 'div[class="EdiDialogSort"]').removeClass().addClass("EdiDialogSortLi");
    document.getElementById('gn' + groupId).className = 'EdiDialogSortCurrent';   
}

function showAddPanel(obj) {
    $(obj).parent().css("position", "relative");
    $(obj).next().show();
    $(obj).next().next().show();
}

function hiddenAddPanel(obj) {
    $(obj).parent().parent().hide();
    $(obj).parent().parent().prev().hide();
    $(obj).parent().parent().parent().css("position", "");
}

function initAddDetail() {
    var addBtns = $("input[name='detailAddButton']");
    if (addBtns == null) return;
    for (var i = 0; i < addBtns.length; i++) {
        var currAddBtn = addBtns[i];

        var captionId = currAddBtn.ctl + "_caption";
        var captionPanel = currAddBtn.ctl + "_panel";

        var AppendHTML = "<div class=\"addName\" style=\"display:none;position:absolute;left:12px;top:26px;z-index:0;overflow:hidden;\"><iframe scrolling=\"no\"></iframe></div>" +
                        "<div class=\"addName\" style=\"display:none;position:absolute;left:12px;top:26px;z-index:1;\"><label>添加</label>" +
                        "<div><input type=\"text\" class=\"addWord\" id=\"" + captionId + "\"/>" +
                        "<input type=\"button\" style=\"background:url(/images/sureBut.gif) no-repeat;width:45px;height:22px;line-height:23px;text-align:center;margin-right:7px;\" onclick=\"if(document.getElementById('" + captionId + "').value==''){alert('名称不能为空');return false;}else{CreateDetailProperty('" + currAddBtn.fullName + "', '" + captionId + "', '" + currAddBtn.ctl + "', '" + captionPanel + "');}\" id=\"" + captionPanel + "\" class=\"sureBtn\" value=\"确定\"/>" +
                        "<input type=\"button\" class=\"cancelBtn\" style=\"background:url(/images/cancelBut.gif) no-repeat;width:45px;height:22px;line-height:23px;text-align:center;\" onclick=\"hiddenAddPanel(this);\" value=\"取消\"/></div>" +
                        "</div>";

        $("input[ctl='" + currAddBtn.ctl + "']").after(AppendHTML);
    }
}

function CreateDetailProperty(dictionaryPropertyName, captionCtlId, dropDownCtlId, addPanelId) {
    var webServicesUrl = '/Commons/AddDictionaryProperty/' + dictionaryPropertyName + '/' + $$(captionCtlId).value;
    $.get(webServicesUrl, null, function(data) {
        var oSel = $$(dropDownCtlId);
        oOpt = document.createElement('option');
        oSel.options.add(oOpt, oSel.options.length);
        oOpt.innerText = $$(captionCtlId).value;
        oOpt.value = data;
        oOpt.selected = true;
        $$(captionCtlId).value = "";
        hiddenAddPanel($$(addPanelId));
    });
}
$(document).ready(initAddDetail);
